﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.ServiceModel;
using MsgService;

namespace MsgServer
{
    public partial class MainForm : Form
    {
        public MainForm()
        {
            InitializeComponent();
        }

        ServiceHost host = null;

        //启动按钮
        private void startBtn_Click(object sender, EventArgs e)
        {
            host = new ServiceHost(typeof(Service));

            NetTcpBinding tcpBind = new NetTcpBinding();

            string address = "net.tcp://localhost:3200/sendMsg";

            host.AddServiceEndpoint(typeof(IService), tcpBind, address);
            host.Opened += delegate { msgLab.Text = "服务已经启动"; };
            host.Open();
        }

        //停止按钮
        private void closeBtn_Click(object sender, EventArgs e)
        {
            if (host.State != CommunicationState.Closed)
            {
                host.Close();
                msgLab.Text = "服务已经停止";
            }
        }
    }
}
